﻿package{
	import flash.display.*;
	import flash.events.*;
	import flash.geom.*;
	import flash.filters.*;
	
	import ascb.display.DraggableSprite;
	
	public class TreeBuilder extends Sprite {
		private var _red:DraggableSprite;
		private var _green:DraggableSprite;
		private var _blue:DraggableSprite;
		private var _white:DraggableSprite;
		
		private var startingLocation:Point;
		
		public function TreeBuilder() {
			createRectangles();
			addEventListeners();
		}
			
			_blue = new DraggableSprite
			_blue.graphics.beginFill(0x0000ff);
			_blue.graphics.drawRoundRect( 0, 50, 10, 10, 2, 2 );
			_blue.graphics.endFill();
		}
		
		private function addEventListeners():void{			
			_blue.addEventListener(MouseEvent.MOUSE_DOWN, pickup);
			_blue.addEventListener(MouseEvent.MOUSE_UP, place);
		}
		
		public function pickup(event:MouseEvent):void{
			startingLocation = new Point();
			startingLocation.x = event.target.x;
			startingLocation.y = event.target.y;
			
			event.target.drag();
			event.target.filters = [ new DropShadowFilter() ];
			
			setChildIndex(DisplayObject(event.target), numChildren - 1);
		}
		
		public function place( event:MouseEvent):void {
			event.target.drop();
			event.target.filters = null;
			
			var dropTargets:Array = getObjectsUnderPoint (new Point(mouseX, mouseY));
			
		}
			
			event.target.x = startingLocation.x;
			event.target.y = startingLocation.y;
		}
		
		
		
	}
}
											